﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BankBooks.aspx.cs" Inherits="Main_Reports_Accounts_AccountBooks_BankBooks"  Culture="en-GB" %>

   <%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Assembly="CalendarExtenderPlus" Namespace="AjaxControlToolkitPlus" TagPrefix="advancedCalender" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Bank Books</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script src="../../../../JavaScript/jquery-1.3.2.min.js" type="text/javascript"></script>
    

    <style type="text/css">
        .TreeView
        {
            border: solid 1px #d6d3ce;
        }
        .TreeView td
        {
            border: solid 1px #d6d3ce;
        }
        .TreeView tr
        {
            page-break-inside: avoid;
            page-break-after: auto;
        }
        .TreeView thead
        {
            display: table-header-group;
        }
        .TreeView tfoot
        {
            display: table-footer-group;
        }
    </style>

    <script type="text/javascript">
//        $(document).ready(function() {
//            $("#tvHierarchyView span").css("width", "10px");
//        });
//    
        function EnabledTabKey(id, e) {
            var keycode;
            if (window.event) {
                keycode = window.event.keyCode;
            }
            else if (e) {
                keycode = e.which;
            }
            else {
                return true;
            }

            if (keycode == 9) {
                // if is the tab key                
                return true;
            }
            else {
                return false;
            }
        }
        function Validation() {
            var flag = true;
            var txtFromdate = document.getElementById("txtFromDate").id;
            var txtTodate = document.getElementById("txtToDate").id;
            if (document.getElementById("txtFromDate").value == '') {
                alert('Specify From date');
                flag = false;
            }
            else if (document.getElementById("txtToDate").value == '') {
                alert('Specify To date');
                flag = false;
            }
            else {
                if (isDate(txtFromdate) && isDate(txtTodate)) {
                    var dateArray = new Array();
                    dateArray = document.getElementById("txtFromDate").value.split("/");
                    var day1 = dateArray[0];
                    var month1 = dateArray[1];
                    var year1 = dateArray[2];
                    dateArray = document.getElementById("txtToDate").value.split("/");
                    var day2 = dateArray[0];
                    var month2 = dateArray[2];
                    var year2 = dateArray[2];

                    if (day1.length < 2) {
                        day1 = '0' + day1;
                    }
                    if (month1.length < 2) {
                        month1 = '0' + month1;
                    }
                    if (day2.length < 2) {
                        day2 = '0' + day2;
                    }
                    if (month2.length < 2) {
                        month2 = '0' + month2;
                    }
                    var date1 = new Date(year1, month1 - 1, day1);
                    var date2 = new Date(year2, month2 - 1, day2);
                    if (date1 > date2) {
                        alert('Date Could Not be less than From Date');
                        document.getElementById(txtFromdate).focus();
                        flag = false;

                    }
                }
                else {
                    flag = false;
                }
            }
            return flag;
        }
        function isDate(txtDateId) {
            // date length should be 10 characters - no more, no less            
            var Ctrl = document.getElementById(txtDateId);
            var txtDate = Ctrl.value;
            var flag = true;

            // extract day, month and year from the txtDate string
            // expected format is dd/mm/yyyy
            var day = '';
            var month = '';
            var year = '';
            var dateArray = new Array();
            var count = 0;
            for (var j = 0; j < txtDate.length; j++) {
                var chara = txtDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid date !');
                return false;
            }
            dateArray = txtDate.split("/");


            day = dateArray[0];
            month = dateArray[1];
            year = dateArray[2];


            if (year.length != 4) {
                alert('Invalid date !');
                return false;
            }
            var finYear = document.getElementById("hidFinyear").value;
            if (month >= 4 && year != parseInt(finYear)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }
            else if (month < 4 && year != (parseInt(finYear) + 1)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }



            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for have only 30 day
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 31) {
                    alert('Date Should not be Greater than 30');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for Febuary 
            else if (month == 2) {
                var leap = year % 4;
                if (leap == 0) {
                    if (day > 29) {
                        alert('february have only 29 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (day > 28) {
                        alert('february have only 28 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
            }
            else if (month > 12) {
                alert('Invalid Date');
                Ctrl.focus();
                flag = false;
            }
            // otherwise return true
            return flag;
        }
        function printPartOfPage() {
            var fromDate = document.getElementById("hidFromDate").value;
            var toDate = document.getElementById("hidToDate").value;
            if (fromDate != '' && toDate != '') {
                window.open('../TrialBalancePrint.aspx', '', 'height=0,width=0,top=5000,left=5000');
            }
            return false
        }
        function OpenMonthlySummary(lid, lname, fromdate, todate) {
            window.open('LedgerDetails.aspx?LID=' + lid + '&LNAME=' + lname + '&FROMDATE=' + fromdate + '&TODATE=' + todate, '', 'height=600,width=900,scrollbars=1,resizable=1,titlebar=1');
        }          
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:HiddenField ID="hidFinyear" runat="server" />
    <div class="divmain">
       <acc:heading ID="Heading" runat="server" HeadingText="Bank Book" /> 
       
    </div>
    <div style="margin-left:5%;">
        <asp:LinkButton ID="hyperChangeDate" runat="server" Text="Change Date"></asp:LinkButton>&nbsp;&nbsp;
        <asp:HyperLink ID="hyperPrint" runat="server" NavigateUrl="#" onclick="return printPartOfPage();"
            Text="Print"></asp:HyperLink>
        <asp:HiddenField ID="hidFromDate" runat="server" />
        <asp:HiddenField ID="hidToDate" runat="server" />
    </div>
    <div id="divPrint" style="margin-bottom: 15px; width:90%; margin-left:5%; margin-right:5%;">
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td align="center" style="margin-bottom: 10px; width: 100%">
                    <asp:Label ID="lblCompanyName" runat="server" Font-Size="14px" Font-Bold="true"></asp:Label>
                </td>
            </tr>
            <tr>
                <td align="center" style="padding: 10px 0px 5px 0px; width: 100%">
                    <asp:Label ID="lblHeading" runat="server" Font-Bold="true"></asp:Label>
                </td>
            </tr>
            <tr>
                <tbwc:treegrid id="tvHierarchyView" runat="server" showexpandcollapse="true" width="100%"
                    cssclass="TreeView" showlines="true" onnodedatabound="tvHierarchyView_RowDataBound"
                    populatenodesfromclient="false" ajaxmode="true">
            <HeaderStyle BackColor="#e3eee3" HorizontalAlign="Center" Font-Bold="true" />
            <NodeStyle Display="Inline" />
            <Columns>
                <asp:TemplateField HeaderText="Particulars">
                    <ItemTemplate>
                        <%# Eval("GName") %></ItemTemplate>
                    <ItemStyle Width="40%" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Opening Balance" ItemStyle-HorizontalAlign="Right">
                    <ItemTemplate>
                        <%# Eval("OpenBal") %></ItemTemplate>
                    <ItemStyle Width="15%" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Debit" ItemStyle-HorizontalAlign="Right">
                    <ItemTemplate>
                        <%# Eval("Debit") %></ItemTemplate>
                    <ItemStyle Width="15%" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Credit" ItemStyle-HorizontalAlign="Right">
                    <ItemTemplate>
                        <%# Eval("Credit") %></ItemTemplate>
                    <ItemStyle Width="15%" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Closing Balance" ItemStyle-HorizontalAlign="Right">
                    <ItemTemplate>
                        <%# Eval("ClosingBal") %></ItemTemplate>
                    <ItemStyle Width="15%" />
                </asp:TemplateField>
            </Columns>
        </tbwc:treegrid>
            </tr>
        </table>
    </div>
    <asp:Panel ID="PanelChangeDate" runat="server" Width="350px" Height="160px" Style="display: none"
        CssClass="modalPopup">
        <div style="width: 80%; margin: 20px 10% 10px 10%;">
            <table>
                <tr>
                    <td>
                        From date
                    </td>
                    <td style="padding-left: 10px">
                        <asp:TextBox ID="txtFromDate" runat="server" CssClass="input" ToolTip="DD/MM/YYYY"
                            Width="100px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        To Date
                    </td>
                    <td style="padding-left: 10px">
                        <asp:TextBox ID="txtToDate" runat="server" CssClass="input" ToolTip="DD/MM/YYYY"
                            Width="100px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <asp:Button ID="btnCangeDate" runat="server" CssClass="button" Text="Ok" OnClick="btnCangeDate_Click"
                            OnClientClick="return Validation()" />&nbsp;
                        <asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" />&nbsp;
                    </td>
                </tr>
            </table>
        </div>
    </asp:Panel>
    <ajaxtoolkit:modalpopupextender id="modalDate" runat="server" cancelcontrolid="btnCancel"
        targetcontrolid="hyperChangeDate" popupcontrolid="PanelChangeDate" backgroundcssclass="modalBackground">
    </ajaxtoolkit:modalpopupextender>
    </form>
</body>
</html>

